﻿<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
    <title></title>
    <style type="text/css">
        #Text1
        {
            height: 137px;
            width: 319px;
        }
        #TextArea1
        {
            height: 88px;
            width: 511px;
        }
        #TextArea2
        {
            height: 67px;
            width: 511px;
        }
    </style>
</head>
<body>
    <p>
        <em>Description:</em></p>
    <p>
        Please find out the nearest and greatest node around the given node(determined 
        by parameter <strong>k</strong>).</p>
    <p>
        <em>Example:</em></p>
    <p>
        <img alt="" src="binarytree.jpg" /></p>
    <p>
        &nbsp;</p>
    <p>
        1.k=10&nbsp;&nbsp;&nbsp; return node.Data=18</p>
    <p>
        2.k=2&nbsp;&nbsp;&nbsp; 
        return node.Data=9</p>
    <p>
        3.k=6&nbsp;&nbsp;&nbsp; return node.Data=7</p>
    <p>
        <em>Something you need know:</em></p>
    <p>
        1.the nearest means 1 step away.(including its parent, and two children if has)</p>
    <p>
        2.the greatest means the found node should greater than given node.</p>
    <p>
        3.if not found, please return <strong>null</strong>. USE TRY 
        CATCH TO CATCH ALL EXCEPTION IS FORBIDEEN</p>
    <p>
        4.No duplicate Data in binary tree.</p>
    <p>
        <em>Signatures:</em></p>
    <p>
        int?
        FindNearestGreatestNode(Node root, int k)
    </p>
    <p>
        <em>DataStructure:
    </em>
    </p>
    <p>
        <textarea id="TextArea1" name="S1">  public class Node
    {
        public int Data { get; set; }
        public Node LeftChild { get; set; }
        public Node RightChild { get; set; }
    }</textarea></p>
    <p>
        Interface:</p>
    <p>
        <textarea id="TextArea2" cols="20" name="S2"> interface IFindNearestGreatestNodeInBinaryTree
    {
        int? FindNearestGreatestNode(Node root, int k);
    }
    </textarea></p>
    <p>
        &nbsp;</p>
    </body>
</html>
